package test;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.Border;
import java.awt.*;

public class MainFrame extends JFrame {
    public MainFrame() {
        super("Main Frame");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        // 创建容器
        Container contentPane = getContentPane();
        contentPane.setLayout(new BorderLayout());

        // 创建左侧和右侧的 JPanel
        JPanel leftPanel = new JPanel();
        JPanel rightPanel = new JPanel();

        // 设置背景颜色以便观察效果
        leftPanel.setBackground(Color.LIGHT_GRAY);
        rightPanel.setBackground(Color.GRAY);

        // 创建边框
        Border border = BorderFactory.createLineBorder(Color.BLACK, 2);

        // 设置边框
        leftPanel.setBorder(border);
        rightPanel.setBorder(border);

        // 创建间距组件
        Component spacing = Box.createRigidArea(new Dimension(20, 20));

        // 将左侧、间距和右侧的组件添加到容器中
        contentPane.add(leftPanel, BorderLayout.WEST);
        contentPane.add(spacing, BorderLayout.CENTER);
        contentPane.add(rightPanel, BorderLayout.EAST);

        // 设置窗口大小
        setPreferredSize(new Dimension(800, 600));
        pack();
        setLocationRelativeTo(null);
        setVisible(true);
    }

    public static void main(String[] args) {
        new MainFrame();
    }
}
